package com.ido.babyshow.action;

import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.ido.babyshow.model.Catalog;
import com.ido.babyshow.service.ICatalogService;


/**
 * 初始化缓存中的数据，放入全局变量
 * @author <a href="mailto:luoshq@neusoft.com">luoshouqiang</a>
 * @version $Revision 1.1 $ 2013-3-5 下午04:13:52
 */
public class InitListener extends  ContextLoaderListener{
    
    
    private static final long serialVersionUID = 1L;
    
    private static final Logger log=LoggerFactory.getLogger(InitListener.class);

    
     public void contextInitialized(ServletContextEvent event){
         super.contextInitialized(event);
         ApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(event.getServletContext());  
         ICatalogService catalogService= (ICatalogService) applicationContext.getBean("catalogService");   
         log.info("-----------初始化数据-----------");
         ServletContext context=event.getServletContext();
         List<Catalog> catalogList=catalogService.selectAllCatalog(); 
         context.setAttribute("catalogList", catalogList);
         log.info("-----------初始化完成-----------"+catalogList.size());
     }
       
}
